<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddFieldProductInput extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasColumn('product', 'input_1')) {
            Schema::table('product', function (Blueprint $table) {
                $table->string('input_1', 80)->comment('输入框1');
            });
        }
        if (!Schema::hasColumn('product', 'input_2')) {
            Schema::table('product', function (Blueprint $table) {
                $table->string('input_2', 80)->comment('输入框2');
            });
        }
        if (!Schema::hasColumn('product', 'input_3')) {
            Schema::table('product', function (Blueprint $table) {
                $table->string('input_3', 80)->comment('输入框3');
            });
        }

        if (!Schema::hasColumn('product', 'original')) {
            Schema::table('product', function (Blueprint $table) {
                $table->unsignedInteger('original')->default(0)->comment('原价');
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (Schema::hasColumn('product', 'input_1')) {
            Schema::table('product', function (Blueprint $table) {
                $table->dropColumn('input_1');
            });
        }

        if (Schema::hasColumn('product', 'input_2')) {
            Schema::table('product', function (Blueprint $table) {
                $table->dropColumn('input_2');
            });
        }

        if (Schema::hasColumn('product', 'input_3')) {
            Schema::table('product', function (Blueprint $table) {
                $table->dropColumn('input_3');
            });
        }

        if (Schema::hasColumn('product', 'original')) {
            Schema::table('product', function (Blueprint $table) {
                $table->dropColumn('original');
            });
        }
    }
}
